//
//  InformationController.m
//  MedicineBox
//
//  Created by dllo on 15/10/5.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "InformationController.h"
#import "AsyncConnection.h"
#import "CommentCollectionCell.h"
#import "DKNightVersion.h"
@interface InformationController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, retain)UICollectionView *collectionV;
@property (nonatomic, retain) NSMutableArray *collectionArray;

@end

@implementation InformationController

- (void)dealloc
{
    
    [_collectionArray release];
    [_collectionV release];
    [super dealloc];
    
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
     
        self.collectionArray = [NSMutableArray array];
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(5, 20, 60, 30);
    [backButton setTitle:@"返回" forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    self.view.backgroundColor = [UIColor colorWithRed:86/255.0 green:137/255.0 blue:156/255.0 alpha:1];
    self.view.nightBackgroundColor = UIColorFromRGB(0x343434);
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height - 60);
    layout.minimumLineSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height - 60) collectionViewLayout:layout];
    _collectionV.dataSource = self;
    _collectionV.pagingEnabled = YES;
    _collectionV.delegate = self;
    _collectionV.contentSize = CGSizeMake(self.view.frame.size.width * _collectionArray.count, self.view.frame.size.height - 60);
    [_collectionV registerClass:[CommentCollectionCell class] forCellWithReuseIdentifier:@"Information"];
    [self.view addSubview:_collectionV];
    [_collectionV release];
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    CommentCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Information" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    cell.type = @"information";
    if (_collectionArray.count != 0) {
        
        [cell getId:[[_collectionArray objectAtIndex:indexPath.item] objectForKey:@"NewsID"]];
        
    }
    
    return cell;
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return _collectionArray.count;

}

- (void)getDic:(NSDictionary *)dic array:(NSArray *)array
{

    [self.collectionArray addObjectsFromArray:array];
    [self.collectionV reloadData];

}

- (void)backButtonAction:(id)sender
{

    [self dismissViewControllerAnimated:YES completion:nil];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
